<template>
  <div>
    <van-notice-bar
      left-icon="volume-o"
      :text="this.detail.title"
    />
     <div class="banner">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
            <van-swipe-item
             v-for="url in this.detail.photo"
             :key="`photo-${url.id}`"
            >
              <img :src="url.url" alt="">
            </van-swipe-item>
        </van-swipe>
     </div>
     <div class="detailMsg">
      <h5>{{this.detail.title}}</h5>
      <p>用券后<b>{{this.detail.price}}</b></p>
      <div class="detailMsg-amount">
         <span>原价<del>{{this.detail.originPrice}}</del></span>
         <span>月销量<b>{{this.detail.saleNum}}</b></span>
       </div>
     </div>
     <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" color="#07c160" />
      <van-goods-action-icon icon="cart-o" to="/cart" text="购物车" />
      <van-goods-action-icon icon="star" text="已收藏" color="#ff5000" />
      <van-goods-action-button type="warning" color="#ffd20b91" @click="addToCart(detail)" text="加入购物车" />
      <van-goods-action-button type="danger" color="#FFD000" text="立即购买" />
    </van-goods-action>
    <van-divider>图片详情</van-divider>
    <ul>
      <li
        v-for="url in this.detail.descContentList"
        :key="`photo-${url.photo.id}`"
        >
        <img :src="url.photo.url" alt="">
      </li>
    </ul>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  name: 'Detail',
  data () {
    return {
      id: 0,
      detail: ''
    }
  },
  created () {
    // console.log(this.$route.query.id)
    this.id = this.$route.query.id
    this.$http.getDetailData(this.id)
      .then(resp => {
        console.log(resp)
        const {
          id,
          title,
          originPrice,
          photo,
          price,
          saleNum,
          descContentList
        } = resp.detail
        this.detail = {
          id,
          title,
          originPrice,
          photo,
          price,
          saleNum,
          descContentList
        }
      })
  },
  methods: {
    ...mapMutations(['addToCart'])
  }
}
</script>

<style lang="scss" scoped>
.detailMsg{
  padding: 0 20px;
  font-size:15px ;
  h5{
    font-weight: normal;
    line-height: 2;
  }
  p{
    font-size: 12px;
    display: flex;
    align-items: center;
    b{
        padding-left: 5px;
        font-size: 25px;
        color: red;
    }
  }
  &-amount{
    margin-top: 5px;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    b{
        font-weight: normal;
    }
  }
}
</style>
